﻿using System.Text;
using WebAppFilterDemo.InterfaceService;

namespace WebAppFilterDemo.Middleware
{
    /// <summary>
    /// 强类型中间件
    /// </summary>
    public class SeasonMiddleware : IMiddleware
    {
        //依赖类型，通过构造函数进行依赖注入
        private readonly ISeasonTips _seasonTips;
        public SeasonMiddleware(ISeasonTips seasonTips)
        {
            _seasonTips = seasonTips;
        }

        //调用依赖的“季节提示类型”，根据当前时间获取当前季节的注意事项，并进行响应输出
        public async Task InvokeAsync(HttpContext context, RequestDelegate next)
        {
            //await context.Response.WriteAsync(_seasonTips.Prompt(DateTimeOffset.Now));
            //return;

            await Console.Out.WriteLineAsync(_seasonTips.Prompt(DateTimeOffset.Now));
            await Console.Out.WriteLineAsync(" SeasonMiddleware - InvokeAsync");
            //调用管道中的下一个中间件
            await next(context);
        }  // END InvokeAsync()


    }  // END Class


}
